package com.content.Controller.artist;

import com.common.Entity.Result;
import com.content.Entity.artist.Category;
import com.content.Service.artist.CategoryService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/getCategoryList")
    public Result getCategoryList(@RequestParam Integer pageNum,
                                  @RequestParam Integer pageSize,
                                  @RequestParam(required = false) String categoriesName){
        PageInfo<Category> pageInfo = categoryService.getCategoryList(pageNum, pageSize, categoriesName);
        return Result.success(pageInfo);
    }

    @PostMapping("/addCategory")
    public Result addCategory(@RequestBody Category category){
        categoryService.addCategory(category);
        return Result.success();
    }

    @PutMapping("/updateCategory")
    public Result updateCategory(@RequestBody Category category){
        categoryService.updateCategory(category);
        return Result.success();
    }

    @DeleteMapping("/deleteCategory/{categoriesId}")
    public Result deleteCategory(@PathVariable("categoriesId") String categoriesId){
        categoryService.deleteCategory(categoriesId);
        return Result.success();
    }

    @GetMapping("/getCategoryById/{categoryId}")
    public Result getCategoryById(@PathVariable("categoryId") String categoryId){
        Category category = categoryService.getCategoryById(categoryId);
        return Result.success(category);
    }
}
